package com.misday.eatup;

import com.misday.eatup.model.FoodsColumns;

import android.content.Context;
import android.database.Cursor;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DigestCursorAdapter extends CursorAdapter {
	
	private Context mContext;
	private int idxFood;
	private int idxPriority;
	private int idxDetail;

	public DigestCursorAdapter(Context context, Cursor c) {
		super(context, c);

		mContext = context;
		
		if (c != null) {
			idxFood = c.getColumnIndex(FoodsColumns.FOOD);
			idxPriority = c.getColumnIndex(FoodsColumns.PRIORITY);
			idxDetail = c.getColumnIndex(FoodsColumns.DETAIL);
		}
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		if (cursor == null || view == null || cursor.getCount() < 1) {
			return;
		}
				
		TextView food = (TextView)view.findViewById(R.id.digest_item_food);
		TextView detail = (TextView)view.findViewById(R.id.digest_item_detail);		
		ImageView priority = (ImageView)view.findViewById(R.id.digest_item_priority);
		
		String valFood = cursor.getString(idxFood);		
		String valDetail = cursor.getString(idxDetail);
		String valPriority = cursor.getString(idxPriority);
		
		food.setText(valFood);
		detail.setText(valDetail);
		/*
		if (TextUtils.equals(FoodsColumns.PRIORITY_6, valPriority)) {priority.setImageResource(R.drawable.p_6);} else 
		if (TextUtils.equals(FoodsColumns.PRIORITY_5, valPriority)) {priority.setImageResource(R.drawable.p_5);} else 
		if (TextUtils.equals(FoodsColumns.PRIORITY_4, valPriority)) {priority.setImageResource(R.drawable.p_4);} else 
		if (TextUtils.equals(FoodsColumns.PRIORITY_3, valPriority)) {priority.setImageResource(R.drawable.p_3);} else 
		if (TextUtils.equals(FoodsColumns.PRIORITY_2, valPriority)) {priority.setImageResource(R.drawable.p_2);} else 
		if (TextUtils.equals(FoodsColumns.PRIORITY_1, valPriority)) {priority.setImageResource(R.drawable.p_1);} else 
		if (TextUtils.equals(FoodsColumns.PRIORITY_0, valPriority)) {priority.setImageResource(R.drawable.p_0);}
		*/
		if (TextUtils.equals(FoodsColumns.PRIORITY_6, valPriority)) {priority.setImageResource(R.drawable.priority_6);} else 
		if (TextUtils.equals(FoodsColumns.PRIORITY_5, valPriority)) {priority.setImageResource(R.drawable.priority_5);} else 
		if (TextUtils.equals(FoodsColumns.PRIORITY_4, valPriority)) {priority.setImageResource(R.drawable.priority_4);} else 
		if (TextUtils.equals(FoodsColumns.PRIORITY_3, valPriority)) {priority.setImageResource(R.drawable.priority_3);} else 
		if (TextUtils.equals(FoodsColumns.PRIORITY_2, valPriority)) {priority.setImageResource(R.drawable.priority_2);} else 
		if (TextUtils.equals(FoodsColumns.PRIORITY_1, valPriority)) {priority.setImageResource(R.drawable.priority_1);} else 
		if (TextUtils.equals(FoodsColumns.PRIORITY_0, valPriority)) {priority.setImageResource(R.drawable.priority_0);}
		
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {

		return View.inflate(context, R.layout.digest_item, null);
	}
	

}
